package gui.charts;

import java.util.LinkedList;

import lbd.TermFreq;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.data.general.PieDataset;

/**
 * Create a pie chart using data from DefaultPieDataset.
 */
public class PieChart3D extends Chart {

	private static final long serialVersionUID = 1L;
	private String chartTitle;

	/**
     * Default constructor.
     *
     * @param title  the frame title.
     */
    public PieChart3D(String chartTitle, LinkedList<TermFreq> termList) {
    	
        super(termList);
        this.chartTitle = chartTitle;
        
    }
    
    /**
     * Default constructor.
     *
     * @param title  the frame title.
     */
    public PieChart3D() {
    	
        super(new LinkedList<TermFreq>());
        this.chartTitle = "";
        
    }

    /**
     * Creates a chart.
     *
     * @param dataset  the dataset.
     *
     * @return A chart.
     */
    protected JFreeChart createChart(PieDataset dataset) {

        JFreeChart chart = ChartFactory.createPieChart3D(
            chartTitle,  									// chart title
            dataset,            							// data
            true,               							// include legend
            true,											// tooltips
            false											// urls	
        );

        PiePlot plot = (PiePlot) chart.getPlot();
        plot.setSectionOutlinesVisible(false);
        plot.setNoDataMessage("No data available");

        return chart;

    }
    
    /**
     * Creates a sample dataset.
     *
     * @return A sample dataset.
     */
    protected PieDataset createDataset() {
    	
        DefaultPieDataset dataset = new DefaultPieDataset();
        
        for( int i = 0 ; i < termList.size() ; i++ ) {
        	
        	dataset.setValue(	termList.get(i).getTerm() + ", " + termList.get(i).getFreq(),
        						termList.get(i).getFreq());
        	
        }
        
        return dataset;
    }
    
}
